package com.zd.controller;/**
 * @Description: StartlistController
 * @Author:pioneer
 * @Date: 2021-07-05
 * @Version:v1.0
 */

import com.zd.service.lnter.*;
import com.zzg.entity.Startlist;
import com.zzg.entity.Transportprotocol;
import com.zzg.entity.Waybill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: StartlistController 发车列表控制器
 * @Author:pioneer
 * @Date: 2021-07-05
 * @Version:v1.0
 */
@Controller
public class StartlistController {

    @Autowired
    private StartlistServicelnter startlistServicelnter;

    @Autowired
    private TransportProtocolServicelnter transportProtocolServicelnter;

    @Autowired
    private WaybillstateServicelnter waybillstateServicelnter;

    @Autowired
    private WaybillServicelnter waybillServicelnter;

    @Autowired
    private TmsRegionServicelnter tmsRegionServicelnter;

    @Autowired
    private ConsigneeServicelnter consigneeServicelnter;

    @Autowired
    private DriverServicelnter driverServicelnter;

    @Autowired
    private DeliveryServicelnter deliveryServicelnter;

    /**
     * 查询发车列表所有信息
     * @param page 页码
     * @param limit 条目数
     * @return map集合
     */
    @RequestMapping("querystart.action")
    @ResponseBody
    public Map<String,Object> querystart(int page, int limit){
        System.out.println ("正在用querystart查询发车列表所有信息");
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",startlistServicelnter.selectStartlist ().size ());
        map.put("data",startlistServicelnter.getPagingquery (page,limit));
        System.out.println (map);
        return map;
    }
    /**
     * 多条件查询发车信息所有信息
     * @return map集合
     */
    @RequestMapping("wherestart.action")
    @ResponseBody
    public Map<String,Object> wherestart(Startlist startlist){
        System.out.println ("运输单号"+startlist.getShipping ());
        System.out.println ("正在用wherestart多条件查询发车信息");
        int page=1;
        int limit=10;
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",startlistServicelnter.conditionalquery (startlist));
        map.put("data",startlistServicelnter.conditionalPagination (startlist,page,limit));
        System.out.println (map);
        return map;
    }

    /**
     * 通过运输单号获发车信息详情
     * @param shipping
     * @return
     */
    @RequestMapping("selectbyid.action")
    @ResponseBody
    public Map<String,Startlist> selectbyid(String shipping){
        System.out.println ("正在用selectbyid通过运输单号获发车信息详情");
        System.out.println ("运输单号"+shipping);
        Startlist startlist=startlistServicelnter.selectstartlistbyid (shipping);
        Map<String,Startlist> map = new HashMap<> ();
        map.put("Startlist",startlist);
        System.out.println (map);
        return map;
    }
    @RequestMapping("updatedepartlist.action")
    public void updatedepartlist(Startlist startlist, HttpServletResponse response) throws IOException {
        System.out.println ("正在用updatedepartlist修改发车列表");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        Waybill waybill= waybillServicelnter.selectWaybillByid (startlist.getShipping ());
        int agree= transportProtocolServicelnter.updateargee (startlist.getDeparturetime(),startlist.getShipping ());
        int waybillstatus=waybillstateServicelnter.updatestateBy (startlist.getTransportstatus(),startlist.getShipping ());
        int getcity=tmsRegionServicelnter.upateTmsRegion (waybill.getArrivalCity (),startlist.getGetcity ());
        int consignee=consigneeServicelnter.updateConsignee (waybill.getConsigneeId (),startlist.getConsignee (),startlist.getReceivingunit ());
        int driver=driverServicelnter.updateDriverBy (startlist.getWagonnumber (),startlist.getDrivers (),startlist.getDriversphone (),startlist.getVehicleremark ());
        int delivery= deliveryServicelnter.updateDelivery (startlist.getShipping (),startlist.getBillingtime (),startlist.getBillingclerk ());
        System.out.println (agree+"\t"+waybillstatus+"\t"+getcity+"\t"+consignee+"\t"+driver+"\t"+delivery);
        if (agree >= 0) {
            out.write("修改成功");
            System.out.println ("执行成功,影响行数" + agree + "行");
        } else {
            System.out.println ("执行失败");
        }
    }

    @RequestMapping("delectdepartlist.action")
    public void delectdepartlist(String shipping, HttpServletResponse response) throws IOException {
        System.out.println ("正在用delectdepartlist删除发车列表");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        int ser=transportProtocolServicelnter.delectagreeByid (shipping);
        int on=waybillstateServicelnter.updatestateBy ("装车完毕",shipping);
        if (ser >= 0) {
            out.write("修改成功");
            System.out.println ("执行成功,影响行数" + ser + "行");
        } else {
            System.out.println ("执行失败");
        }
    }
}
